package com.jdrx.ocp.service;

import com.jdrx.ocp.beans.entity.*;
import com.jdrx.ocp.dao.*;
import com.jdrx.platform.commons.rest.exception.BizException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 基础接口实现类
 */
@Service
public class BasicInfoService {
    private static final Logger logger = LoggerFactory.getLogger(UserService.class);

    @Autowired
    private UserDAO userDAO;
    @Autowired
    private RoleDAO roleDAO;
    @Autowired
    private ResourceDAO resourceDAO;
    @Autowired
    private DeptDAO deptDAO;
    @Autowired
    private PlatformDAO platformDAO;

    /**
     * 根据ID查询部门
     * @param id
     * @return
     */
    public DeptPO findDeptByIdFast(Long id) throws BizException{
        try {
            return deptDAO.getById(id);
        }catch (Exception e){
            logger.error(e.getMessage(), e);
            throw new BizException("获取数据失败！");
        }
    }

    /**
     * 根据ID查询用户
     * @param id
     * @return
     */
    public UserPO findUserByIdFast(Long id) throws BizException{
        try {
            return userDAO.getById(id);
        }catch (Exception e){
            logger.error(e.getMessage(), e);
            throw new BizException("获取数据失败！");
        }
    }

    /**
     * 根据ID查询角色
     * @param id
     * @return
     */
    public RolePO findRoleByIdFast(Long id) throws BizException{
        try {
            return roleDAO.getById(id);
        }catch (Exception e){
            logger.error(e.getMessage(), e);
            throw new BizException("获取数据失败！");
        }
    }

    /**
     * 根据ID查询资源
     * @param id
     * @return
     */
    public ResourcePO findResourceByIdFast(Long id) throws BizException{
        try {
            return resourceDAO.getById(id);
        }catch (Exception e){
            logger.error(e.getMessage(), e);
            throw new BizException("获取数据失败！");
        }
    }



    /**
     * 根据ID查询平台信息
     * @param id
     * @return
     * @throws BizException
     */
    public PlatformPO findPlatformByIdFast (Long id) throws BizException {
        try {
            return platformDAO.getById(id);
        }catch (Exception e){
            logger.error(e.getMessage(), e);
            throw new BizException("获取数据失败！");
        }
    }

}
